package com.example.last.controller;

import com.example.last.common.Result;
import com.example.last.entity.Log;
import com.example.last.entity.Params;
import com.example.last.service.LogService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RequestMapping("/log")
@RestController
public class LogController {
    @Resource
   private LogService logService;
    @GetMapping("/search")
    public Result findBySearch(@Param("params") Params params){
        PageInfo<Log> info = logService.findBySearch(params);
        return Result.success(info);
    }
    @PostMapping
    public Result save(@RequestBody Log log){
        logService.add(log);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        logService.delete(id);
        return Result.success();
    }

    //批量删除
    @PutMapping("/batch")
    public Result batchdel(@RequestBody List<Log> list){
        for(Log log : list){
            logService.delete(log.getId());
        }
        return Result.success();
    }

}
